<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改轮播图')" />
	<th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-planting-edit" th:object="${planting}" enctype="multipart/form-data">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
            <h4 class="form-header h4">基本信息</h4>
            <div class="form-group">	
				<label class="col-sm-2 control-label">图片：</label>
				<div class="col-sm-8">				
					<input id="imageUrl" name="imageUrl" th:field="*{imageUrl}" class="form-control" type="hidden">
					<img id="imageUrlSrc" width="200px" height="200px" onclick="avator()"/>
					
				</div>
				
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label"><span style="color: red; ">*点击图片进行图片选择</span></label>
				
			</div>
			<div class="form-group">
				<div id="preview" style="display: none;">
						<p>
							上传文件： <input id="file" type="file" name="file" />
						</p>
					</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-2 control-label"><span style="color: red; ">*</span>排序：</label>
				<div class="col-sm-3">
					<input id="line" name="line" th:field="*{line}" class="form-control" type="text" required>
				</div>
				
				<label class="col-sm-2 control-label">标题：</label>
				<div class="col-sm-3">
					<input id="title" name="title" th:field="*{title}" class="form-control" type="text">
				</div>
			</div>



			
			
			<div class="form-group">	
			
				<label class="col-sm-2 control-label">商户：</label>
				<div class="col-sm-3">
					<select id="schoolId" name="schoolId" class="form-control m-b" th:field="*{schoolId}" onchange="func()">			
						<option  th:each="dept:${deptList}"
							th:value="${dept.deptId}" th:text="${dept.deptName}"></option>
				</select>
				</div>
				
				<label class="col-sm-2 control-label">商品：</label>
				<div class="col-sm-3">
					<!-- <input id="goodId" name="goodId" th:field="*{goodId}" class="form-control" type="text"> -->
					<select id="goodId" name="goodId" class="form-control m-b" >
					    
						<option th:each="goods:${goodsList}"
							th:value="${goods.id}" th:text="${goods.goodsName}" th:field="*{goodId}"></option>
					</select>
				</div>
			</div>
		
			<div class="form-group">
				<label class="col-sm-2 control-label">banner类型：</label>
				<div class="col-sm-3">
					<!-- <input id="goodId" name="goodId"  class="form-control" type="text"> -->
					<select id="type" name="type" class="form-control m-b" th:field="*{type}">
						<option value=""></option>
						<option value=1>平台banner</option>
						<option value=2>闪送超市banner</option>
						<option value=3>首页左banner</option>
						<option value=4>首页右上banner</option>
						<option value=5>首页右下banner</option>
												
					</select>
				</div>
				<label class="col-sm-2 control-label">状态：</label>
				<div class="radio col-sm-3">
					<label> <input type="radio" value="1" id="state"
						name="state" th:field="*{state}">启用
					</label> <label> <input type="radio" value="0" id="state"
						name="state" th:field="*{state}">隐藏
					</label>
				</div>
			</div>
			
			<h4 class="form-header h4">改动信息</h4>
			
			<div class="form-group">	
				<label class="col-sm-2 control-label">建立用户：</label>
				<div class="col-sm-3">
					<input id="createBy" name="createBy" th:field="*{createBy}" class="form-control" type="text"  readonly="readonly">
				</div>
				
				<label class="col-sm-2 control-label">修改用户：</label>
				<div class="col-sm-3">
					<input id="updateBy" name="updateBy" th:field="*{updateBy}" class="form-control" type="text"  readonly="readonly">
				</div>
			</div>
			
			<div class="form-group">	
				<label class="col-sm-2 control-label">建立日期：</label>
				<div class="col-sm-3">
					<input id="createDate" name="createDate" th:field="*{createDate}" class="form-control" type="text"  readonly="readonly">
				</div>
				
				<label class="col-sm-2 control-label">修改日期：</label>
				<div class="col-sm-3">
					<input id="updateDate" name="updateDate" th:field="*{updateDate}" class="form-control" type="text"  readonly="readonly">
				</div>
			</div>
			
			
			 
		</form>
    </div>
    <div th:include="include::footer"></div>
    <th:block th:include="include :: select2-js" />
    <script type="text/javascript">
		var prefix = ctx + "Planting/planting";
		$("#form-planting-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/edit", $('#form-planting-edit').serialize());
	        }
	    }
		
		var img = document.getElementById('imageUrlSrc');
		var fileinput = document.getElementById('imageUrl');
		if (fileinput.value != '') {
			img.src = fileinput.value;
		}
		
		
		var preview = document.querySelector('#preview');
		var eleFile = document.querySelector('#file');
		eleFile.addEventListener('change', function() {
			var file = this.files[0];
			// 确认选择的文件是图片                
			if (file.type.indexOf("image") == 0) {
				var reader = new FileReader();
				reader.readAsDataURL(file);
				reader.onload = function(e) {
					// 图片base64化
					var newUrl = this.result;
					//preview.style.backgroundImage = 'url(' + newUrl + ')';
					$("#imageUrlSrc").attr("src", newUrl);
					$("input[name=imageUrl]").val(newUrl);				
				};
			}
		});
		
		function avator() {
			$("#file").click();
		}
		
		/* $("#goodId").select2({
            //data: data,
            placeholder:'请选择',//默认文字提示
            tags: true,//允许手动添加
            allowClear: true,//允许清空              
            ajax: {
                  url: prefix+"/searchGood",
                  type:'GET',
                  dataType: 'json',
                  data: function(){ return {'schoolId':$('#schoolId').val()}},
                  async: false,
                  cache:false,
                  processResults: function (data) {
                    return {
                      results: data.goodsList
                    };
                  }
                }             
          }) */
          
		 /* function func(){
			 
			 var vs = $('#schoolId  option:selected').val();
			 alert(vs);
		} */
		
		 function func(){
			    var oSel = document.getElementById("goodId");//获取供应商的下拉信息goodId
			    var oOp = oSel.children; //获取select列表的所有子元素。
			        for(var i=0;i<oOp.length;i++)   
			        {//将供应商的下拉菜单的数据清除
			            oSel.removeChild(oOp[i]);  //循环删除所有子元素
			        }
			    var objS = document.getElementById("schoolId");//获取配送员的信息
			    var schoolId = objS.options[objS.selectedIndex].value;//获取配送员下拉选定的数据
			     //根据地址和配送员信息发送一个ajax查询，获取相应的配送员信息
			     $.ajax({
			         url:prefix + "/searchGood",
			         data:{
			                schoolId:schoolId
			                },
			        success : function(data) {//将查询到的供应商信息放在供应商的select标签框中
			        	document.getElementById("goodId").innerHTML
		                = "<option value = "+"0"+">"+"无商品"+"</option>" ;
			            if(data.length!=0){//绑定的供应商显示
			                for(var i=0;i<data.length;i++){
			                    $("#goodId").append("<option value = "+data[i].id+">"+data[i].goodsName+"</option>");
			                }
			            }else{
			                document.getElementById("goodId").innerHTML
			                = "<option value = "+"0"+">"+"无商品"+"</option>" ;
			                document.getElementById("goodId").innerHTML
			                = "<option value = "+"0"+">"+"无商品"+"</option>" ;
			                 $.messager.alert('输入错误', '本商户无商品','info');
			                return;
			            }
			        }
			     });  				
			 }
		 
		
		
		
         
       
	</script>
</body>
</html>
